package com.tianma315.admin.check.controller;


import java.util.Arrays;

import com.tianma315.admin.common.base.BaseController;
import com.tianma315.admin.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.check.domain.KeepSampleDO;
import com.tianma315.admin.check.service.KeepSampleService;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2019-07-08 16:57:00 | wen</small>
 */
@Controller
@RequestMapping("/check/keepSample")
public class KeepSampleController extends BaseController{
	@Autowired
	private KeepSampleService keepSampleService;
	
	@GetMapping()
	@RequiresPermissions("check:keepSample:keepSample")
	String KeepSample(){
	    return "check/keepSample/keepSample";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("check:keepSample:keepSample")
	public Result<Page<KeepSampleDO>> list(Integer pageNumber, Integer pageSize, KeepSampleDO keepSampleDTO){
		// 查询列表数据
        Page<KeepSampleDO> page = keepSampleService.keepSamplePage(pageNumber,pageSize,keepSampleDTO);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("check:keepSample:add")
	String add(){
	    return "check/keepSample/add";
	}

	@GetMapping("/edit/{keepSampleId}")
	@RequiresPermissions("check:keepSample:edit")
	String edit(@PathVariable("keepSampleId") Integer keepSampleId,Model model){
		KeepSampleDO keepSample = keepSampleService.selectById(keepSampleId);
		model.addAttribute("keepSample", keepSample);
	    return "check/keepSample/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("check:keepSample:add")
	public Result<String> save( KeepSampleDO keepSample){
		keepSample.setCreateBy(getUserId().intValue());
		keepSample.setSampleMan(getUserId());
		keepSample.setKeepSampleMan(getUserId());
		if(keepSampleService.addKeepSample(keepSample)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("check:keepSample:edit")
	public Result<String>  update( KeepSampleDO keepSample){
		keepSampleService.updateById(keepSample);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("check:keepSample:remove")
	public Result<String>  remove( Integer keepSampleId){
		if(keepSampleService.deleteKeepSample(keepSampleId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("check:keepSample:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] keepSampleIds){
//		keepSampleService.deleteBatchIds(Arrays.asList(keepSampleIds));
		for (Integer id:keepSampleIds) {
			keepSampleService.deleteKeepSample(id);
		}
		return Result.ok();
	}
	
}
